#include "PreClient.h"
#include "D3DDemo1.h"

D3DDemo1::D3DDemo1(void)
{
}

D3DDemo1::~D3DDemo1(void)
{
}

bool D3DDemo1::Setup()
{
	// Nothing to setup in this sample.
	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
		&proj,
		D3DX_PI*0.5f,
		800.0f/600.0f,
		1.0f,
		1000.0f);
	IDirect3DDevice9* Device = RenderSystem::getSingleton().getD3DDevice();
	Device->SetTransform(D3DTS_PROJECTION,&proj);
	Device->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);

	D3DXVECTOR3 pos(5,0,-10);
	D3DXVECTOR3 target(0,0,0);
	D3DXVECTOR3 up(0,1,0);

	D3DXMATRIX view;
	D3DXMatrixLookAtLH(&view,&pos,&target,&up);
	Device->SetTransform(D3DTS_VIEW,&view);
	Device->SetRenderState(D3DRS_LIGHTING,false);

	return true;
}

void D3DDemo1::Cleanup()
{
	// Nothing to cleanup in this sample.
}

bool D3DDemo1::Display(float timeDelta)
{
	IDirect3DDevice9* Device = RenderSystem::getSingleton().getD3DDevice();
	if( Device ) // Only use Device methods if we have a valid device.
	{
		// Instruct the device to set each pixel on the back buffer black -
		// D3DCLEAR_TARGET: 0x00000000 (black) - and to set each pixel on
		// the depth buffer to a value of 1.0 - D3DCLEAR_ZBUFFER: 1.0f.
		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);

		D3DXMATRIX scaleMat;
		D3DXMatrixScaling(&scaleMat,2.f,2.f,2.f);
		Device->SetTransform(D3DTS_WORLD,&scaleMat);

		ID3DXMesh* mesh = 0;
		D3DXCreateTeapot(Device, &mesh, 0);

		Device->BeginScene();
		mesh->DrawSubset(0);
		Device->EndScene();

		mesh->Release();
		mesh = 0;
		// Swap the back and front buffers.
		Device->Present(0, 0, 0, 0);
	}
	return true;
}